package com.Iron.Listener;

import com.Iron.Config.SpringConfig1;
import com.Iron.Service.AccountService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


public class ContextLoaderListener implements ServletContextListener {

    private final String CONTEXT = "contextConfigLocation";

    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("listener start");
 /*       ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
        sce.getServletContext().setAttribute("applicationContext",context);*/
        ServletContext con = sce.getServletContext();
        String initParameter = sce.getServletContext().getInitParameter(CONTEXT).substring("classpath:".length());
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(initParameter);
        con.setAttribute("application", context);

    }

}
